package com.mall.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.mapper.OmsOrderReturnReasonMapper;
import com.mall.pojo.OmsOrderReturnReason;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class OmsOrderReturnReasonApiImpl implements OmsOrderReturnReasonApi {

    @Autowired
    private OmsOrderReturnReasonMapper omsOrderReturnReasonMapper;

    /**
     * 添加用户退货原因
     *
     * @param omsOrderReturnReason
     */
    @Override
    public Integer createOrderReturnReason(OmsOrderReturnReason omsOrderReturnReason) {
        Integer createNum = omsOrderReturnReasonMapper.insert(omsOrderReturnReason);
        return createNum;
    }

    /**
     * 分页查询用户退货原因
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public Page<OmsOrderReturnReason> findOrderReturnReasonList(Integer pageNum, Integer pageSize) {
        Page<OmsOrderReturnReason> page = new Page<>(pageNum, pageSize);

        //创建查询条件
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.orderByDesc(OmsOrderReturnReason::getSort);
        return omsOrderReturnReasonMapper.selectPage(page, queryWrapper);
    }

    /**
     * 根据id进行数据回显
     * @param id
     * @return
     */
    @Override
    public OmsOrderReturnReason findOrderInfoById(Integer id) {
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OmsOrderReturnReason::getId,id);
        OmsOrderReturnReason omsOrderReturnReason = omsOrderReturnReasonMapper.selectOne(queryWrapper);
        return omsOrderReturnReason;
    }
    /**
     * 根据id删除单个或批量删除数据
     * @param ids
     */
    @Override
    public Integer deleteOrderReturnReasonByIds(List<Integer> ids) {
        //添加查询条件
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OmsOrderReturnReason::getId,ids);
        //执行删除方法
        Integer deleteNum = omsOrderReturnReasonMapper.delete(queryWrapper);

        return deleteNum;

    }




    /**
     * 修改回显信息
     * @param omsOrderReturnReason
     * @return
     */
    @Override
    public Integer updateOrderInfoReturn(OmsOrderReturnReason omsOrderReturnReason) {
        //创建条件
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(omsOrderReturnReason.getId()!=null,OmsOrderReturnReason::getId,omsOrderReturnReason.getId());
        //调用方法进行修改
        Integer updateNum = omsOrderReturnReasonMapper.update(omsOrderReturnReason, queryWrapper);

        return updateNum;
    }

    /**
     * 修改退货原因的状态信息
     * @param ids
     * @param status
     * @return
     */
    @Override
    public Integer updateOrderInfoReturnStatus(List<Integer> ids, Integer status) {
        //添加修改条件
        LambdaQueryWrapper<OmsOrderReturnReason> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(OmsOrderReturnReason::getId,ids);
        //把修改的信息封装起来
        OmsOrderReturnReason omsOrderReturnReason = new OmsOrderReturnReason();
        omsOrderReturnReason.setStatus(status);
        //调用方法根据条件进行修改
        Integer updateNum = omsOrderReturnReasonMapper.update(omsOrderReturnReason, queryWrapper);
        return updateNum;
    }


}
